### Jay C. Kao
### This R script reproduces the descriptive statistics reported in the main text of the book chapter
### Last edited: Dec. 27th, 2022

library(tidyverse)
library(readxl)
setwd("~/Google Drive/[A]Projects/Experimental Asian Politics")
article <- read_excel("experiments in asian politics.xlsx")

# sample size
n <- 45

    ########################################
    ## I. the ratio of experimental types ## 
    ########################################

ratio.field <- 9/n
ratio.lab <-5/n
ratio.survey <- 34/n
prop <- c(ratio.lab, ratio.survey, ratio.field)
exp.type <- c("Lab", "Survey", "Field")
exp.type <- factor(exp.type, levels = c("Lab", "Survey", "Field"))
df.prop <- data.frame(proportion = prop,
                      type = exp.type)

# Visualize the result
df.prop <- df.prop %>% 
  mutate(labels = scales::percent(prop))

ggplot(df.prop, aes(x = "", y = prop, fill = type)) +
  geom_col(color = "black") +
  geom_label(aes(label = labels), color = "white",
             position = position_stack(vjust = 0.5), size=3,
             show.legend = FALSE) +
  scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9"), 
                    name="Experimental\nMethod",
                    labels=c("Lab", "Survey", "Field")) +
  coord_polar(theta = "y") + 
  theme_void()

# The percentage of conjoint is 20.5% among survey experiments
# All conjoint analyses are seen in the past three years (since 2020)
ratio.conjoint.survey <- 7/34

# the ratio of subject types
ratio.sub.citizen <- 40/n
ratio.sub.politician <- 4/n
ratio.sub.firm <- 2/n

      #############################
      ## II. the ratio of region ## 
      #############################

ratio.region.east <- sum(str_count(article$Regions, "East")) / n
ratio.region.south <-sum(str_count(article$Regions, "South Asia")) / n
ratio.region.west <- sum(str_count(article$Regions, "West")) / n
ratio.region.southeast <- sum(str_count(article$Regions, "Southeast"))/ n

prop.region <- c(ratio.region.east, ratio.region.south, 
                 ratio.region.west, ratio.region.southeast)
exp.region <- c("East Asia", "South Asia", "West Asia", "Southeast Asia")
exp.region <- factor(exp.region, levels = c("East Asia", "South Asia", 
                                    "West Asia", "Southeast Asia"))

df.prop.region <- data.frame(proportion = prop.region,
                             region = exp.region)

df.prop.region <- df.prop.region %>% 
  mutate(labels = scales::percent(prop.region))

ggplot(df.prop.region, aes(x = "", y = prop.region, fill = exp.region)) +
  geom_col(color = "black") +
  geom_label(aes(label = labels), color = "white",
             position = position_stack(vjust = 0.5), size=5,
             show.legend = FALSE) +
  scale_fill_manual(values = c("#BE2A3E", "#EC754A",
                               "#EACF65", "#3C8D53"), 
                    name="Regions",
                    labels=c("East Asia", "South Asia",
                             "West Asia", "Southeast Asia")) +
  coord_polar(theta = "y") + 
  theme_void()

      #####################################
      ## III. the ratio of country types ## 
      #####################################

china.n <- sum(str_count(article$Country, "China"))
taiwan.n <- sum(str_count(article$Country, "Taiwan"))
jp.n <- sum(str_count(article$Country, "Japan"))
sk.n <- sum(str_count(article$Country, "South Korea"))
india.n <- sum(str_count(article$Country, "India"))
pakistan.n <- sum(str_count(article$Country, "Pakistan"))
afghanistan.n <- sum(str_count(article$Country, "Afghanistan"))
bangladesh.n <- sum(str_count(article$Country, "Bangladesh"))
vietnam.n <- sum(str_count(article$Country, "Vietnam"))
indonesia.n <- sum(str_count(article$Country, "Indonesia"))
philippines.n <- sum(str_count(article$Country, "Philippines"))
iraq.n <- sum(str_count(article$Country, "Iraq"))
jordan.n <- sum(str_count(article$Country, "Jordan"))
turkey.n <- sum(str_count(article$Country, "Turkey"))
lebanon.n <- sum(str_count(article$Country, "Lebanon"))
israel.n <- sum(str_count(article$Country, "Israel"))
Kuwait.n <- sum(str_count(article$Country, "Kuwait"))
qatar.n <- sum(str_count(article$Country, "Qatar"))
uae.n <- sum(str_count(article$Country, "UAE"))
bahrain.n <- sum(str_count(article$Country, "Bahrain"))
saudi.n <- sum(str_count(article$Country, "Saudi Arabia"))

country <- c("China", "Taiwan", "Japan","South Korea","India","Pakistan","Afghanistan",
             "Bangladesh","Vietnam","Indonesia","Philippines","Iraq",
             "Jordan","Turkey","Lebanon","Israel","Kuwait","Qatar",
             "UAE","Bahrain","Saudi Arabia")
number <- c(china.n, taiwan.n, jp.n, sk.n, india.n, pakistan.n, afghanistan.n, bangladesh.n, vietnam.n,
            indonesia.n, philippines.n, iraq.n, jordan.n, turkey.n, lebanon.n, israel.n, 
            Kuwait.n, qatar.n, uae.n, bahrain.n, saudi.n)

dot.df <-data.frame(country = country,
                    number = number)


ggplot(dot.df, aes(x = number, y = reorder(country, number))) +
  geom_point(size=3) +
  theme_bw() +
  theme(panel.grid.major.x = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.y = element_line(colour = "grey60", linetype = "dashed"),
        axis.text.y = element_text(size = 15),
        axis.title.x = element_text(size = 15)) +
  scale_x_continuous(breaks = seq(1,15,1)) +
  labs(x = "Frequency", y = "")

dev.off()
